home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / killexpr / RCS / killexpr,v < prev    next >
Text File  |  1991-07-16  |  2KB  |  100 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    jhh:1.1; strict;
  6. comment  @# @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.28.23.00.59;  author jhh;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @#! /sprite/cmds/perl
  26. #
  27. # This perl script kills all processes that have any of the pattern
  28. # arguments in their command line.  The processes are first sent a 
  29. # SIGTERM, then a SIGKILL.  There is a race condition due to a process
  30. # exiting between the time it is found and the signal is sent.  This
  31. # will cause the kill to fail.
  32. #
  33. # $Header: /sprite/lib/forms/RCS/proto.csh,v 1.3 90/02/20 17:10:35 douglis Exp $ SPRITE (Berkeley)
  34. #
  35. # Copyright 1990 Regents of the University of California
  36. # Permission to use, copy, modify, and distribute this
  37. # software and its documentation for any purpose and without
  38. # fee is hereby granted, provided that the above copyright
  39. # notice appear in all copies.  The University of California
  40. # makes no representations about the suitability of this
  41. # software for any purpose.  It is provided "as is" without
  42. # express or implied warranty.
  43. #
  44.  
  45. $name = $0;
  46.  
  47. do 'getopts.pl';
  48. do Getopts('h:');
  49.  
  50. if ((defined($opt_h)) && ($opt_h eq '')) {
  51.     $error = 1;
  52. }
  53.  
  54. if ($#ARGV < 0) {
  55.     $error = 1;
  56. }
  57. if ($error == 1) {
  58.     printf("Usage: %s [-h host] word1 word2 ...\n",$name);
  59.     exit(1);
  60. }
  61.  
  62. $count = 0;
  63. $pattern = join('|',@@ARGV);
  64. if (defined($opt_h)) {
  65.     open(INPUT, "f =ps@@$opt_h |") || print("Open failed: $@@\n");
  66.     $remote = 1;
  67. } else {
  68.     open(INPUT, "ps |") || print("Open failed: $@@\n");
  69. }
  70. if (defined($remote)) {
  71.     $user = `whoami`;
  72.     chop($user);
  73. }
  74. while(<INPUT>) {
  75.     if (defined($remote)) {
  76.     ($userName, $pid, $d1, $d2, $d3, $d4, $d5, $d6, $command) = 
  77.         split(' ',$_,9);
  78.     } else {
  79.     ($pid, $d1, $d2, $command) = split(' ',$_,4);
  80.     }
  81.     if ($command =~ /$pattern/o) {
  82.     if (defined($remote)) {
  83.         if ($userName ne $user) {
  84.         next;
  85.         }
  86.     }
  87.     if (($pid =~ /[0-9a-f]+/) && (hex($pid) != $$)) {
  88.         $#goners++;
  89.         $goners[$#goners] = hex($pid);
  90.         print "$pid ";
  91.     }
  92.     }
  93. }
  94. if ($#goners >= 0) {
  95.     print "\n";
  96.     kill (15, @@goners) || print("Kill failed: $!\n");
  97.     kill (9, @@goners) || print("Kill failed: $!\n");
  98. }
  99. @
  100.